# -*- encoding: utf-8 -*-
"""
@File:        DatasourceController.py
@Author:      Little duo
@Time:        2024/4/12 9:35 
@Contact:     1049041957@qq.com
"""
from fastapi import APIRouter, Request
from fastapi import Depends

from config.get_db import get_db
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
from module_admin.service.login_service import LoginService
from module_data_server.datasource.DatasourceService import *
from utils.log_util import *
from utils.page_util import PageResponseModel
from utils.response_util import *

datasourceController = APIRouter(prefix='/dataServer/datasource')


# datasourceController = APIRouter(prefix='/dataServer/datasource', dependencies=[Depends(LoginService.get_current_user)])

@datasourceController.get("/list", response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('dataServer:datasource:list'))])
async def getDatasourceList(
        request: Request,
        query: DatasourcePageQueryModel = Depends(DatasourcePageQueryModel.as_query),
        query_db: Session = Depends(get_db)
):
    try:
        # 获取分页数据
        result = DatasourceService.getDatasourceList(query_db, query, is_page=True)
        logger.info('数据源列表获取成功')
        return ResponseUtil.success(model_content=result)
    except Exception as e:
        logger.exception(e)
        return ResponseUtil.error(msg=str(e))
